package test0ne.多线程;

import java.util.concurrent.*;

public class TestCallable {

    private static class CallableDemo implements Callable{

        @Override
        public Integer call() throws Exception {
            int sum = 0;
            for (int i = 0; i < 10000; i++) {
                sum += 1;
            }

            return sum;
        }
    }

    public static void main(String[] args) {
        CallableDemo callableDemo = new CallableDemo();

        FutureTask<Integer> work = new FutureTask<>(callableDemo);

        new Thread(work).start();

        try {
            Integer sum = work.get();
            System.out.println(sum);
            System.out.println("----------------------------");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
